<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%-- 分页start --%>
<c:if test="${pageBean.totalPage > 1}">
	<ul class="pagination">
	  	<%-- 当前是第一页 上一页按钮不可点击--%>
		<c:if test="${pageBean.page == 1}">
			<li><a href="javascript:;">&laquo;</a></li>
		</c:if>

		<%-- 当前非第一页  上一页按钮可点击--%>
		<c:if test="${pageBean.page > 1}">
			<li><a href="javascript:toPage(${fn:escapeXml(pageBean.page)-1});">&laquo;</a></li>
		</c:if>
	  
	  <!-- 当前页码以及之前的页码 -->
		<c:choose>
			<c:when test="${pageBean.page <= 4}">
				<c:forEach var="v" begin="1" end="${pageBean.page}">
					<c:if test="${pageBean.page == v}">
						<li class="active"><a href="javascript:;">${fn:escapeXml(v) }</a></li>
					</c:if>
					<c:if test="${pageBean.page != v}">
						<li><a href="javascript:toPage(${fn:escapeXml(v) });">${fn:escapeXml(v) }</a></li>
					</c:if>
				</c:forEach>
			</c:when>
			<c:otherwise>
				<a href="javascript:toPage(1);">1</a>
				<span>...</span>
				<c:forEach var="v" begin="${pageBean.page - 2 }" end="${pageBean.page}">
					<c:if test="${pageBean.page == v}">
						<li class="active"><a href="javascript:;">${fn:escapeXml(v) }</a></li>
					</c:if>
					<c:if test="${pageBean.page != v}">
						<li><a href="javascript:toPage(${fn:escapeXml(v) });">${fn:escapeXml(v) }</a></li>
					</c:if>
				</c:forEach>
			</c:otherwise>
		</c:choose>

		<!-- 补全当前页码后面的页码 -->
		<c:choose>
			<c:when test="${pageBean.page >= pageBean.totalPage - 3 || pageBean.totalPage - 3 <= 0}">
				<c:forEach var="v" begin="${pageBean.page + 1 }" end="${pageBean.totalPage}">
					<c:if test="${pageBean.page == v}">
						<li class="active"><a href="javascript:void(0)">${fn:escapeXml(v) }</a></li>
					</c:if>
					<c:if test="${pageBean.page != v}">
						<li><a href="javascript:toPage(${fn:escapeXml(v) });">${fn:escapeXml(v) }</a></li>
					</c:if>
				</c:forEach>
			</c:when>
			<c:otherwise>
				<c:forEach var="v" begin="${pageBean.page + 1 }" end="${pageBean.page+2}">
					<c:if test="${pageBean.page == v}">
						<li class="active"><a href="javascript:void(0)">${fn:escapeXml(v) }</a></li>
					</c:if>
					<c:if test="${pageBean.page != v}">
						<li><a href="javascript:toPage(${fn:escapeXml(v) });">${fn:escapeXml(v) }</a></li>
					</c:if>
				</c:forEach>
				<span>...</span>
				<li><a href="javascript:toPage(${fn:escapeXml(pageBean.totalPage) });">${fn:escapeXml(pageBean.totalPage) }</a></li>
			</c:otherwise>
		</c:choose>

		<%-- 当前页是最后一页 --%>
		<c:if test="${pageBean.page == pageBean.totalPage}">
			<li><a href="javascript:;">&raquo;</a></li>
		</c:if>

		<%-- 当前页非最后一页 --%>
		<c:if test="${pageBean.page < pageBean.totalPage}">
			<li><a href="javascript:toPage(${fn:escapeXml(pageBean.page)+1});">&raquo;</a></li>
		</c:if>
	  
	</ul>
</c:if>
<%-- 分页end --%>